package tr.edu.boun.phys.springmassmodel.synth;

import tr.edu.boun.phys.springmassmodel.Mass;
import tr.edu.boun.phys.springmassmodel.Spring;
import tr.edu.boun.phys.springmassmodel.SpringMassModel;
import tr.edu.boun.phys.springmassmodel.Vector2D;

public class ScanCircularModel extends ScannedSynth {	

	@Override
	public SpringMassModel createSpringMassModel() {
		int N = 128;
		double radius = 15;
		double x, y;
		SpringMassModel circularModel = new SpringMassModel();
		
		for(int i =0; i<N; i++) {
			x = radius * Math.cos(2*Math.PI*i/N);
			y = radius * Math.sin(2*Math.PI*i/N);
			Vector2D r = new Vector2D(x, y);
			Vector2D v = new Vector2D(0.0, 0.0);
			circularModel.addMass( new Mass(0.4, r, v) );
			//System.out.println( model.getNumberOfMasses() );
		}
		
		Vector2D v = new Vector2D(0.0, 0.0);
		Vector2D r = new Vector2D(0.0, 0.0);
		Mass middleMass = new Mass(3.0, r, v);
		middleMass.setConstraint(Mass.NO_FREEDOM);
		circularModel.addMass( middleMass );
		
		for(int i=0; i<N; i++) {
			Spring s = new Spring( circularModel.getMass(i), circularModel.getMass( (i+1)%N) );
			s.setK(0.001);
			s.setInitialLength( s.getInitialLength()/100 );
			circularModel.addSpring( s );
			
			s = new Spring( circularModel.getMass(i), circularModel.getMass( N ) );
			s.setK(0.0005);
			circularModel.addSpring( s );
		}
		return circularModel;
	}

	@Override
	public int[] getSamples() {
		int N = model.getNumberOfMasses()-1;
		int[] samples = new int[N];
		for(int i=0; i<N; i++) {
			//double y0 = model.getMass(0).getInitialLocation().y;
			//double x0 = model.getMass(0).getInitialLocation().x;
			
			double y = model.getMass(i).getLocation().y;
			double x = model.getMass(i).getLocation().x;
			samples[i] = (int)(100*(Math.sqrt(y*y+x*x)-15));
			//System.out.println("i: "+i+", "+model.getMass(i).getLocation().x+", "+model.getMass(i).getLocation().y);
		}
		return samples;
	}

}
